package com.blb.service.impl;

import com.blb.mapper.EmployeeMapper;
import com.blb.pojo.Employee;
import com.blb.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeDAO;

    @Override
    public List<Employee> findAll() {
        return employeeDAO.selectAll();
    }

    @Override
    public List<Employee> findEmployeesLikeName(String name) {
        return employeeDAO.selectEmployeesLikeName(name);
    }

    @Override
    public Employee findById(Long id) {
        try {
            return employeeDAO.selectById(id);
        }catch (EmptyResultDataAccessException ex){
            return null;
        }
    }

    @Override
    public void updateEmployee(Employee employee) {
        employeeDAO.updateEmployee(employee);
    }
}
